package com.yc;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @program: concurrent
 * @description: socket
 * @author: zy
 * @create: 2022-01-13 11:27
 */
public class Test3_Client {
    //Test3的客户端程序
    public static void main(String[] args) throws IOException {
        //                       192.168.16.222
        Socket s=new Socket("localhost", 10002);
        System.out.println(  "联接成功."+ s );

//        //用输入流来接时间
       try(     InputStream iis=s.getInputStream();      ){
            byte[] bs=new byte[1024];
            int length=-1;
           System.out.println("客户端等待服务端的响应");
            while(  (length=iis.read(bs,0, bs.length)) !=-1){
                String str=new String(   bs, 0, length );
                System.out.println(   "服务端的响应:"+ str);
            }
       }catch(Exception ex){
           ex.printStackTrace();
       }
        System.out.println("客户端断开与服务器的联接");
       s.close();
    }
}
